#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll T,n,arr[100005];
ll power[15];
ll c,ans = 0;
int get(ll x,int di){
    return (power[di-1]&x?1:0);
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;
    power[0] = 1;
    for(int i = 1;i<=16;i++){
        power[i] = power[i-1]*2;
    }
    while(T--){
        cin>>n;
        ans = 0;
        for(int i = 1;i<=n;i++) cin>>arr[i];
        for(int x = 0;x<power[n];x++){
            c = 0;
            for(int i = 1;i<=n;i++){
                for(int j = i-1;j>=1;j--){
                    if(get(x,j)==get(x,i)){
                        c+=(arr[i]==arr[j]? arr[i]:0);
                        break;
                    }
                }
            }
            //cout<<c<<endl;
            ans = max(ans,c);
        }
        cout<<ans<<endl;
    }
    return 0;
}
